using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace WXB.RenderNode
{
    public struct sInitHyerlinkData
    {
        public string text;
        public Color color;
        public UIFont font;
        public int fontSize;
        public bool bUnderline;
        public string appendText;
        public bool bGlint;
    }

    class HyperlinkNode : TextNode
    {
        const string NodeType = "HyperlinkNode";

        public override string getType()
        {
            return NodeType;
        }

        public override void init(object obj)
        {
            sInitHyerlinkData linkData = (sInitHyerlinkData)(obj);
            d_text = linkData.text;
            d_textColor = linkData.color;
            d_pFont = linkData.font;
            d_bUnderline = linkData.bUnderline;
            d_appendText = linkData.appendText;
            d_bGlint = linkData.bGlint;
            d_fontSize = linkData.fontSize;
            d_mouseEnterColour = Color.red;
        }

        public override NodeBase clone()
        {
            HyperlinkNode node = new HyperlinkNode();
            node.d_text = d_text;
            node.d_pFont = d_pFont;
            node.d_textColor = d_textColor;
            node.d_bUnderline = d_bUnderline;

            node.d_appendText = d_appendText;
            node.d_mouseEnterColour = d_mouseEnterColour;
            node.d_bMouseEnter = d_bMouseEnter;
            node.d_bUpdate = d_bUpdate;

            return node;
        }

        public override string getAppend()
        {
            return d_appendText;
        }

        public override void onMouseEnter()
        {
            d_bUpdate = true;
            d_bMouseEnter = true;

            foreach (UIWidget widget in UIWidgetList)
            {
                //                 UILabel label = widget as UILabel;
                //                 label.color = d_mouseEnterColour;
                TweenColor.Begin(widget.gameObject, 0.1f, d_mouseEnterColour);
            }
        }

        public override void onMouseLeave()
        {
            d_bUpdate = true;
            d_bMouseEnter = false;

            foreach (UIWidget widget in UIWidgetList)
            {
                TweenColor.Begin(widget.gameObject, 0.1f, d_textColor);
            }
        }

        protected override Color getTextColour()
        {
            if (d_bMouseEnter == true)
                return d_mouseEnterColour;

            return d_textColor;
        }

        protected override bool isUnderLine()
        {
            // 			if (d_bMouseEnter == true)
            // 				return true;
            // 
            // 			return d_bUnderline;

            return true;
        }

        public override bool IsHyText()
        {
            return true;
        }

        public virtual string GetHyText()
        {
            return d_appendText;
        }

        protected string d_appendText;
        private Color d_mouseEnterColour;
        private bool d_bMouseEnter;
        private bool d_bUpdate;
    };
}
